package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CaseInfo;
import cn.wolfcode.crm.domain.CompensationInfo;
import cn.wolfcode.crm.query.CompensationInfoQuery;
import cn.wolfcode.crm.service.ICompensationInfoService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/compensationInfo")
public class CompensationInfoController {
    @Autowired
    private ICompensationInfoService compensationInfoService;

    //视图
    @RequestMapping("/view")
    public String index() {
        return "compensate/compensationInfo";
    }


    //查询所有
    @RequestMapping("/selectAll")
    @ResponseBody
    public Object selectAll() {
        return compensationInfoService.listAll();
    }

    @RequestMapping("/query")
    @ResponseBody
    public Object query(CompensationInfoQuery qo) {
        return compensationInfoService.query(qo);
    }

    //新增/编辑
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(CompensationInfo entity,Long caseInfoId) {
        try {
            compensationInfoService.save(entity,caseInfoId);
        } catch (Exception ex) {
            ex.printStackTrace();
            return new JsonResult().mark(ex.getMessage());
        }
        return new JsonResult();
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        compensationInfoService.delete(id);
        return new JsonResult();
    }

    //查询单行数据
    @RequestMapping("/selectById")
    @ResponseBody
    public CompensationInfo selectById(Long id) {
        return compensationInfoService.selectById(id);
    }
    //查询单行数据
    @RequestMapping("/selectCaseInfoById")
    @ResponseBody
    public CaseInfo selectCaseInfoById(Long id) {
        return compensationInfoService.selectCaseInfoById(id);
    }
}
